package com.ugoodtech.mdcc.web.controller;

import com.google.common.collect.Lists;
import com.mysema.query.BooleanBuilder;
import com.ugoodtech.mdcc.core.domain.Nation;
import com.ugoodtech.mdcc.core.domain.QNation;
import com.ugoodtech.mdcc.core.repository.NationRepository;
import com.ugoodtech.mdcc.web.common.BizConstants;
import com.ugoodtech.mdcc.web.dto.ServerResponse;
import com.ugoodtech.mdcc.web.exception.BizException;
import com.ugoodtech.mdcc.web.exception.EnumBizError;
import com.ugoodtech.mdcc.web.pojo.vo.PerformanceReportStatisticsResponse;
import com.ugoodtech.mdcc.web.service.LocationService;
import com.ugoodtech.mdcc.web.service.PerformanceReportStatisticsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import static com.ugoodtech.mdcc.web.dto.ServerResponse.MSG_SUCCESS;


@RestController
@RequestMapping("/v1")
public class LocationController {

	@Autowired
	private LocationService locationService;

	/**
	 *此方法用于业绩报告-数据统计模块，通过输入项获取省份
	 * @param key 输入的关键字
	 */
	@RequestMapping(value = "/getLocationsByKey", method = RequestMethod.GET)
	public ServerResponse getLocationsByKey(@RequestParam(value = "key", required = false, defaultValue = "") String key) throws Exception {
		return ServerResponse.success(MSG_SUCCESS,locationService.getLocationByNameVOs(key));
	}
	@RequestMapping(value = "/locations", method = RequestMethod.GET)
	public ServerResponse getLocations(
			@RequestParam(required = false, defaultValue = BizConstants.Location.REPUBLIC_OF_PEOPLE_CODE) String code) throws Exception {
		if (code.equals(BizConstants.Location.REPUBLIC_OF_PEOPLE_CODE)) {
			return ServerResponse.success(MSG_SUCCESS, locationService.getLocationVOs(code));
		}
		return ServerResponse.success(MSG_SUCCESS, locationService.getInteriorLocationByNameVOs(code));
	}
}
